<?php

class WEEKLYDataParser extends DOMDataParser {

    public function parseData($data) {
        $data = '<!DOCTYPE html>' . $data;
        $dom = new DOMDocument();
        /* there might be errors, who knows what we're getting */
        if (!@$dom->loadHTML(mb_convert_encoding($data, 'HTML-ENTITIES', $this->encoding))) {
            $dom = false;
        } else {
            $dom = $this->rewriteAbsoluteUrls($dom);
        }

        $contents = array();
        if ($dom) {
            if ($weather = $dom->getElementById('forecast0')) {
                $elements = $weather->getElementsByTagName('tr');
                $element1 = $elements->item(0)->getElementsByTagName('th');
                $element2 = $weather->getElementsByTagName('td');
                for ($i = 0;$i < 7;$i++) {
                    $str1 = $dom->saveXML($element1->item($i+1));
                    $content[0] = str_replace("<br/>", " ", $str1);
                    $str2 = $dom->saveXML($element2->item($i));
                    $content[1] = str_replace("forecast/taiwan/inc/city/../../", "", $str2);
                    $str3 = $dom->saveXML($element2->item($i+7));
                    $content[2] = str_replace("forecast/taiwan/inc/city/../../", "", $str3);
                    $contents[] = $content;
                }
            }
        }
        return $contents;
    }
}
